<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> 
<head>
<title>Regular Expressions Sample</title>
<link rel="stylesheet" type="text/css" href="../../../docs/rotor.css">
</head>

<body>		


<h1> Regular Expressions Sample</h1>


<h2>Sample Overview</h2>


<p>This sample demonstrates usage of the <b>RegEx</b> class and regular expressions.&nbsp; 
The user is shown a variety of regular expressions and is allowed to enter 
search text to which to apply the expression.&nbsp; To illustrate 
characteristics of matches, groups, and captures, these collections are used to 
output the expression match results to the console.</p>


<p>The sample has three main sections:</p>


<ul>
  <li>Regular expression matches. This section demonstrates using 
  <b>RegEx.Match</b> and all the collections used by the <b>RegEx</b> class.</li>
  <li>Replacement expression results. This section demonstrates using replacement 
  patterns to make changes to some existing text through the <b>RegEx.Replace()</b> 
  method.</li>
  <li>Substitution expression results. This section shows demonstrates replacement patterns to make changes only to matched text through 
  <b>RegEx</b> and the <b>RegEx.Match.Results()</b> method.</li>
</ul>


<p>See source code for more detailed comments.</p>

<h3>Common Useful Regular Expressions.</h3>


<table width="90%" border="1">
  <tr>
    <th>Use</th>
    <th>Expression</th>
  </tr>
  <tr>
    <td>Social Security number</td>
    <td>\d{3}-\d{2}-\d{4}</td>
  </tr>
  <tr>
    <td>US Phone number</td>
    <td>((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}</td>
  </tr>
  <tr>
    <td>US Postal code</td>
    <td>\d{5}(-\d{4})?</td>
  </tr>
  <tr>
    <td>Internet e-mail address</td>
    <td>[\w-]+@([\w-]+\.)+[\w-]+</td>
  </tr>
  <tr>
    <td>Internet URL</td>
    <td>http://([\w-]\.)+[\w-](/[\w- ./?%=]*)?</td>
  </tr>
  <tr>
    <td>Simple password (digit)</td>
    <td>^(?=.*\d).{4,8}$</td>
  </tr>
  <tr>
    <td>Advanced password (upper, lower, digit)</td>
    <td>^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$</td>
  </tr>
  <tr>
    <td>Common file masks</td>
    <td>^(.+)\\(.+)\.(.+)</td>
  </tr>
  <tr>
    <td>Major credit card</td>
    <td>\d{4}-?\d{4}-?\d{4}-?\d{4}</td>
  </tr>
</table>



<h2>Sample Source and Build Output Locations</h2>


<p>The sample source is found in sscli20\samples\howto\regularexpressions.</p>


<p>The source file is:</p>


<ul class="none">
  <li><a href="regularexpressions.cs">regularexpressions.cs</a></li>
</ul>


<p>The build output location is %_NTTREE%\samples\howto\regularexpressions.&nbsp; 
The output file is an executable assembly named regularexpressions.exe.</p>


<h2>Building the Sample</h2>


<p>All samples are built from the buildall script.&nbsp;  </p>


<p>You can also build all the 
samples by switching to the root of the sample directory, sscli20\samples, and typing 
<code>build -c</code>.</p>


<p>You can build this specific sample  by switching to the sample directory and typing 
<code>build -c</code>.</p>


<h2>Running the Sample</h2>


These steps require that the Shared Source CLI (SSCLI) be already built and 
functional.<ol>
  <li>Run env.bat. </li>
  <li>Switch to the %_NTTREE%\samples\howto\regularexpressions directory.</li>
  <li>Type the following command:<blockquote>


<p>clix regularexpressions.exe</p>


  </blockquote>


  </li>
</ol>


<hr>


<p><i>Copyright (c) 2006 Microsoft Corporation. All rights reserved.</i></p>
</body> 
</html>